Multiply two integers without using the * operatorΒΆ
Multiply two integers without using the * operator.
def multiply(x, y):
if y < 0:
return -multiply(x, -y)
elif y == 0:
return 0
elif y == 1:
return x
else:
return x + multiply(x, y - 1)
# test
print(multiply(3, 5));
Output:
15